package com.ky.manage.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.ky.manage.R;
import com.ky.manage.model.CheckItemModel;

/**
 * 检查选择
 *
 * @author zhaoyan
 * @date 2020-09-04
 */
public class CheckItemView extends LinearLayout {
    private Context mContext;
    private TextView labelTv;
    private TextView stateTv;
    private ImageView arrowRightIv;

    public CheckItemView(Context context) {
        this(context, null);
    }

    public CheckItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CheckItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public CheckItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context, attrs);
    }

    /**
     * 初始化view
     *
     * @param context
     * @param attrs
     */
    private void initView(Context context, AttributeSet attrs) {
        mContext = context;
        LayoutInflater.from(context).inflate(R.layout.check_item_view, this, true);
        labelTv = findViewById(R.id.label_tv);
        stateTv = findViewById(R.id.state_tv);
        arrowRightIv = findViewById(R.id.right_iv);
        setOnClickListener(v -> {
            if (null != checkItemClick) {
                checkItemClick.onItemClick(checkItemModel);
            }
        });
    }

    public void setShowArrowRightIv(boolean show) {
        arrowRightIv.setVisibility(show ? VISIBLE : INVISIBLE);
    }

    public void setLabelTxt(String labelTxt) {
        labelTv.setText(labelTxt);
    }

    public void setStateTxt(String stateTxt) {
        stateTv.setText(stateTxt);
    }

    private CheckItemModel checkItemModel;
    private OnCheckItemClick checkItemClick;

    public void setCheckItemModel(CheckItemModel checkItemModel, OnCheckItemClick checkItemClick) {
        this.checkItemModel = checkItemModel;
        this.checkItemClick = checkItemClick;
    }

    public static interface OnCheckItemClick {
        void onItemClick(CheckItemModel checkItemModel);
    }
}
